#ifndef SERVICE_H
#define SERVICE_H
#include <iostream>
#include <vector>
#include <QVector>
#include <HalconCpp.h>
#include <QMap>
#include <mutex>
#include "NetWork/tcp.h"
namespace Ser {

struct Location_Error
{
    Location_Error() {}
    Location_Error(QString modeFile,QString mode,double length,double width,double angle,double angle_error,
                   double length_error,double width_error,double area_error,double image_error,double diameter_error){
        this->modeFile=modeFile;
        this->mode=mode;
        this->length=length;
        this->width=width;
        this->angle=angle;
        this->angle_error=angle_error;
        this->length_error=length_error;
        this->width_error=width_error;
        this->area_error=area_error;
        this->image_error=image_error;
        this->diameter_error=diameter_error;
    }
    QString modeFile;
    QString mode;//模板形状
    double length;//长度
    double width;//宽度
    double angle;//角度
    double angle_error;//角度误差
    double length_error;//长度误差
    double width_error;//宽度误差
    double area_error;//面积误差
    double image_error;//图像误差
    double diameter_error;//直径误差
};

//结果坐标与面积
struct Coords
{
    Coords() {}
    Coords(double row,double colum):row(row),colum(colum) {}
    double row;
    double colum;
    bool isNull=true;
};
struct TCP_Struct
{
    TCP_Struct() {}
};
struct UPD_Struct
{
    UPD_Struct() {}
};
class Service
{
public:
    static Service* Instance();//返回Service实例
    QVector<QString> Open_Deploy_File(QString path);//打开配置文件
    QString getFindText(QVector<QString> v,QString txtName);//返回查找到的文本参数
    void Deploy_ARI_ErrorRate(QString modeID);//部署算法与误差率
    double QString_trun_Double(QString str);//30%转0.3
    QString Extract_variable(QString str,QString start_Symbol="<",QString end_Symbol=">");//<name>变成name,提取变量名
    Coords Excute_ARI();//执行算法
    bool find_HObject(QString s,HalconCpp::HObject *image);//返回指定图像或者区域
    bool find_HTuple(QString s,HalconCpp::HTuple *tuple);//返回指定HTuple
    bool readImage();//获取图片

private:
    Service();
public:
    QVector<QString> ari_Vector;//配置算子与参数
    Location_Error location_Error;//配置误差率参数
    QMap<QString,HalconCpp::HObject> image_Map;//运行过程产生的HObject参数
    QMap<QString,HalconCpp::HTuple>  parameter_Map;//运行过程产生的HTuple参数
    HalconCpp::HObject image;//当前图像
    std::mutex m;//线程锁
    TCP tcp;//tcp通信
};

}

#endif // SERVICE_H
